package com.shujvku.test1.controller;


        import com.alibaba.fastjson.JSON;
        import com.shujvku.test1.bean.User;

        import com.shujvku.test1.dao.UserDao;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.web.bind.annotation.CrossOrigin;
        import org.springframework.web.bind.annotation.RequestBody;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RestController;

        import java.util.HashMap;

@RestController
public class LoginController {
    @Autowired
    UserDao userDao;

    @CrossOrigin
    @RequestMapping("/login")
    public  String login(@RequestBody User user)
    {
        String flag="error";
        User us = userDao.getUserByMassage(user.getUsername(),user.getPassword());
        System.out.println(("user:"+us));
        HashMap<String,Object> res =new HashMap<>();
        if(us!=null){
            flag="ok";
        }
        res.put("flag",flag);
        res.put("user",user);
        String res_json = JSON.toJSONString(res);
        return res_json;
    }

//    public String userLogin(@RequestBody User user) {
//        System.out.println("User : " + user);
//        String str = "error";
//        int count = userDao.getUserByMassage(user.getUsername(), user.getPassword());
//        if (count > 0) {
//            str = "ok";
//        }
//        return str;
//    }
}

